#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>   
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/async.h>
#include <iostream>

int main()
{
    spdlog::flush_every(std::chrono::seconds(1));        // 刷新频率
    spdlog::flush_on(spdlog::level::level_enum::debug);  // 刷新的最低等级
    spdlog::set_level(spdlog::level::level_enum::debug); // 全局日志输出等级(每个日志器可以独立设置)
    
    // 初始化异步日志输出的线程配置(节点数, 线程数)
    spdlog::init_thread_pool(4096, 1);

    // 创建异步日志器
    auto logger = spdlog::stdout_color_mt<spdlog::async_factory>("async-logger"); 
    // auto logger = spdlog::basic_logger_mt("file-logger", "sync.log");

    // 设置输出格式
    logger->set_pattern("[%n][%H:%M:%S][%t][%-8l] %v");
    logger->trace("spdlog print: {}", "this is a spdlog-demo file");
    logger->debug("spdlog print: {}", "this is a spdlog-demo file");
    logger->info("spdlog print: {}", "this is a spdlog-demo file");
    logger->warn("spdlog print: {}", "this is a spdlog-demo file");
    logger->error("spdlog print: {}", "this is a spdlog-demo file");
    logger->critical("spdlog print: {}", "this is a spdlog-demo file");

    std::cout << "test finish\n";

    return 0;
}